<?php


namespace app\portal\service;


use app\admin\model\NavMenuModel;

class NavService
{
    // 获取当前页面所属的全部分类
    public function getAllNav($pageId)
    {
        $data = [
            "action" => "portal/Page/index",
            "param" => [
                "id" => $pageId
            ]
        ];

        $model = new NavMenuModel();
        /** @var NavMenuModel $nav */
        $nav = $model->where([
            "href" => json_encode($data)
        ])->find();
        if ($nav->parent) {
            return [
                'item' => $nav->parent,
                'children' => $model->subNavMenusTreeArray($nav->parent->id)
            ];
        } else {
            return [
            ];
        }

    }
}